import { _decorator, Component, EventTarget, Node, director } from 'cc';
import { EventType } from './EventType';
const { ccclass, property } = _decorator;

///////////////// 事件信号 //////////////////////
const EventHandle: EventTarget = new EventTarget()

////////////////////////////////////////////////


@ccclass('EventManager')
export class EventManager extends Component
{
    public static instance: EventManager
    // public static Event:Array<String>

    onLoad()
    {
        EventManager.instance = this
        director.addPersistRootNode(this.node)
        // EventManager.Event = new Array<String>()
    }

    RegisterEvent<TFunction extends (...any: any[]) => void>(event: EventType, callback: TFunction, thisArg?: any)
    {
        EventHandle.on(event, callback, thisArg)
    }

    DispatchEvent(event: EventType, arg0?: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any)
    {
        EventHandle.emit(event, arg0, arg1, arg2, arg3, arg4)
    }

    DeleteEvent<TFunction extends (...any: any[]) => void>(event: EventType, callback: TFunction, thisArg?: any)
    {
        EventHandle.off(event, callback, thisArg)
    }

    OnGameStart()
    {
        
    }

}


